package cn.itsource.controller.app;



import cn.dev33.satoken.annotation.SaIgnore;
import cn.itsource.pojo.app.dto.AddCarDto;
import cn.itsource.pojo.app.dto.AppRegisterDto;
import cn.itsource.pojo.domain.CustomerCar;
import cn.itsource.result.R;
import cn.itsource.service.ICustomerCarService;
import cn.itsource.service.ICustomerService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Tag(name = "App用户端API",description = "App用户端API")
@RestController
@RequestMapping("/app/customer")
public class AppDriverController {

    @Autowired
    private ICustomerService customerService;

    @Autowired
    private ICustomerCarService customerCarService;

    @Operation( summary= "添加车辆",description = "添加车辆")
    @Parameter(name = "addcar",description = "添加车辆",required = true)
    @PostMapping("/addcar")
    @SaIgnore
    public R addCar(@RequestBody @Valid AddCarDto addCarDto){
        customerCarService.addCar(addCarDto);
        return R.success();
    }

    @Operation( summary= "车辆列表",description = "车辆列表")
    @Parameter(name = "carlist",description = "车辆列表",required = true)
    @GetMapping("/carlist")
    @SaIgnore
    public R carList(){
        List<CustomerCar> cars = customerCarService.carList();
        return R.success(cars);
    }

    @Operation( summary= "用户注册",description = "用户注册")
    @Parameter(name = "driver",description = "保存的对象",required = true)
    @PostMapping("/register")
    @SaIgnore
    public R register(@RequestBody @Valid AppRegisterDto appRegisterDto){
        return R.success(customerService.register(appRegisterDto));
    }


}
